# 文件读取为一行文本
def readFile(filePah):
  fileString = ''
  with open(filePah, 'r', encoding="utf8") as f:
    fileString = f.read()
  return fileString

def handleCSS(filename):
  fileString = readFile(filename)
  return f"GM_addStyle(`{fileString}`);"

def concatAll(head, filePaths, toFileName):
  scriptString = readFile(head) + '\n'
  for filePath in filePaths:
    if filePath.split('.')[-1] == 'css':
      scriptString += handleCSS(filePath) + '\n'
    else:
      scriptString += readFile(filePath) + '\n'

  userScriptName = toFileName + '.user.js'
  with open(userScriptName, 'w', encoding="utf8") as f:
    f.write(scriptString)

concatAll(
  './head.user.js',
  [
    # 这里放你要连接的 css/js 文件名
    './chunk-vendors.css',
    './app.css',
    './iconfont.min.css',
    './css.min.css',
    
    './app.js',
    './chunk-vendors.js'
  ],
  'mfwComparePrice'
)